import {isPlainObject,isString} from 'lodash';
import ic_nav_kj from '@/assets/image/main/icon/ic_nav_kj.png';
import ic_nav_dt from '@/assets/image/main/icon/ic_nav_dt.png';
import ic_nav_swtt from '@/assets/image/main/icon/ic_nav_swtt.png';
import ic_nav_tp from '@/assets/image/main/icon/ic_nav_tp.png';
import ic_nav_sp from '@/assets/image/main/icon/ic_nav_sp.png';
import ic_nav_wb from '@/assets/image/main/icon/ic_nav_wb.png';
import ic_nav_wbs from '@/assets/image/main/icon/ic_nav_wbs.png';
import ic_nav_sjdt from '@/assets/image/main/icon/ic_nav_sjdt.png';

import ppt_bg from '@/assets/image/main/icon/ppt_bg.png';
import map_bg from '@/assets/image/main/icon/map_bg.png';
import swdt_bg from '@/assets/image/main/icon/swdt_bg.png';
import img_bg from '@/assets/image/main/icon/img_bg.png';
import video_bg from '@/assets/image/main/icon/video_bg.png';
import word_bg from '@/assets/image/main/icon/word_bg.png';
import sjdt_bg from '@/assets/image/main/icon/sjdt_bg.png';
import text_bg from '@/assets/image/main/icon/text_bg.png';

const changeStyle = (obj) => {
    for (let key in obj) {
        //重新赋值自己之前定义的less变量值
        document
            .getElementsByTagName('body')[0]
            .style.setProperty(`--${key}`, obj[key]);
    }
};

export const subject={
    DL:{
        allbackground: '#0081FF',
        allfontcolor: '#fff',
        searchbackground: '#fff',
        titleBgColor:'rgba(0, 129, 255, .5)'
    },
    LS:{
        allbackground: '#F48A06',
        allfontcolor: '#fff',
        searchbackground: '#fff',
        titleBgColor:'rgba(242, 170, 80, .5)'
    },
    YY:{
        allbackground: '#5D6B7E',
        allfontcolor: '#fff',
        searchbackground: '#fff',
        titleBgColor:'rgba(93, 107, 126, .5)'
    }
}
const setTheme = (themeName=null) => {
    let themeConfig = isString(themeName)?subject[themeName]:false;
    if(isPlainObject(themeConfig)){
        sessionStorage.setItem("themeConfig", JSON.stringify(themeConfig)); 
    }else{
        let themeConfig=sessionStorage.getItem("themeConfig");
        try{
            themeConfig=isString(themeConfig) && isPlainObject(JSON.parse(themeConfig))?themeConfig:null;
        }catch(e){
            themeConfig=null;
        }
        themeConfig=themeConfig?themeConfig:subject['DL'];
    }
    changeStyle(themeConfig);
};

export const ResourceTypeList=[
    { name: '课件', iconName: ic_nav_kj, bgName:ppt_bg, searchIconName:ppt_bg, count: 0, type: 0, typeText: 'ppt', fileExt: ['pptx', 'ppt', 'PPTX', 'PPT'] },
    { name: '地图', iconName: ic_nav_dt, bgName:map_bg, searchIconName:map_bg,  count: 0, type: 1, typeText: 'layer', fileExt: ['efgl'] },
    { name: '思维导图', iconName: ic_nav_swtt, bgName:swdt_bg, searchIconName:swdt_bg, count: 0, type: 2, typeText: 'mindmapping', fileExt: ['km'] },
    { name: '图片', iconName: ic_nav_tp, bgName:img_bg, searchIconName:img_bg,  count: 0, type: 3, typeText: 'image', fileExt: ['jpg', 'jpeg', 'png', 'gif'] },
    { name: '视频', iconName: ic_nav_sp, bgName:video_bg, searchIconName:video_bg,  count: 0, type: 4, typeText: 'video', fileExt: ['mp4'] },
    { name: 'Word', iconName: ic_nav_wb, bgName:word_bg, searchIconName:word_bg,  count: 0, type: 5, typeText: 'doc', fileExt: ['doc', 'docx'] },
    { name: '时间导图', iconName: ic_nav_sjdt, bgName:sjdt_bg, searchIconName:sjdt_bg,  count: 0, type: 6, typeText: 'timeline', fileExt: ['xlsx'] },
    { name: '文本', iconName: ic_nav_wbs, bgName:text_bg, count: 0, searchIconName:text_bg,  type: 7, typeText: 'txt', fileExt: ['txt'] },
  ]

export default setTheme;